package io.ai.arch.java.ai;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.nio.file.*;
import java.util.List;

@RestController
@RequestMapping("/novel")
public class NovelAnalysisController {

    @Autowired
    private NovelAnalysisService analysisService;

    @PostMapping(path = "/analyze", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    public List<String> analyzeNovel(@RequestParam("file") MultipartFile file) throws Exception {
        Path tempFile = Files.createTempFile("novel", ".txt");
        file.transferTo(tempFile.toFile());
        return analysisService.analyzeNovel(tempFile);
    }
}